/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.intec.matsab.dao;

import edu.intec.matsab.persistence.PersistenceManager;
import edu.intec.matsab.persistence.Seccion;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import javax.persistence.Query;

/**
 *
 * @author matilde
 */
public class SeccionDAO extends BasicoDAO {

    //Seccion.findByTrimestreAsignatura
    public static List<Seccion> buscarSeccionesdeAsignatura(String trimestre, String asignatura) {
        EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
        EntityManager manager = emf.createEntityManager();

        List<Seccion> listSeccion = new ArrayList<Seccion>();

        try {
            Query query = manager.createNamedQuery("Seccion.findByTrimestreAsignatura");
            query.setParameter("idTrimestre", trimestre);
            query.setParameter("idAsignatura", asignatura);
            listSeccion = (List<Seccion>) query.getResultList();

        } catch (PersistenceException exception) {
            exception.printStackTrace();
        } finally {
            manager.close();
        }

        return listSeccion;
    }

    public static List<Seccion> buscarSeccionesPorEstado(char estado) {
        EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
        EntityManager manager = emf.createEntityManager();

        List<Seccion> listSeccion = new ArrayList<Seccion>();

        try {
            Query query = manager.createNamedQuery("Seccion.findSeccionesByStatus");
            query.setParameter("idEstado", estado);
            listSeccion = (List<Seccion>) query.getResultList();

        } catch (PersistenceException exception) {
            exception.printStackTrace();
        } finally {
            manager.close();
        }

        return listSeccion;
    }
    //Seccion.findSeccion

    public static Seccion buscarSeccion() {
        EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
        EntityManager manager = emf.createEntityManager();

        Seccion seccion = new Seccion();

        try {
            Query query = manager.createNamedQuery("Seccion.findSeccion");
            seccion = (Seccion) query.getSingleResult();

        } catch (PersistenceException exception) {
            exception.printStackTrace();
        } finally {
            manager.close();
        }

        return seccion;
    }
}
